﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using RM.Entities.Data;
using RM.Entities;

namespace RM.Web
{
    /// <summary>
    /// Summary description for $codebehindclassname$
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class DownloadZip : IHttpHandler
    {
        TestManager manager = new TestManager();

        public void ProcessRequest(HttpContext context)
        {
            int id;
            int.TryParse(context.Request.QueryString["id"],out id);
            context.Response.ContentType = "application/octet-stream";
            Test result = manager.GetById<Test>(id);
            if (result!=null && result.SolutionFile != null)
            context.Response.OutputStream.Write(result.SolutionFile, 0, result.SolutionFile.Length - 1);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
